package com.wyd.observer.demo02;

import com.wyd.observer.demo02.Observer.Display;
import com.wyd.observer.demo02.Observer.Observer;
import com.wyd.observer.demo02.Subject.Subject;

/**
 * @author Yudi Wang
 * @date 2022/1/6 11:24
 */
public class PressureDisplay implements Observer, Display {

    private int pressure;

    public PressureDisplay(Subject subject) {
        subject.registerObserver(this);
    }

    public void update(Subject subject) {
        if (subject instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) subject;
            this.pressure = weatherData.getPressure();
            display();
        }
    }

    public void display() {
        System.out.println("当前气压为：" + pressure);
    }
}
